import {
	getSeriesList
} from '@/api/collection/index.js'

export default {
	namespaced: true,
	state: {
		collectionSeries: [],
		boxSeries: [],
		vintageSeries: []
	},
	mutations: {
		setSeries(state, {
			collectionSeries,
			boxSeries,
			vintageSeries
		}) {
			state.collectionSeries = collectionSeries
			state.boxSeries = boxSeries
			state.vintageSeries = vintageSeries
		}
	},
	actions: {
		//获取系列
		async getSeries({
			state,
			commit
		}, refresh = false) {
			if (!refresh && state.collectionSeries.length && state.boxSeries.length) {
				return Promise.resolve({
					collectionSeries: state.collectionSeries,
					boxSeries: state.boxSeries
				})
			}
			let collectionSeries = getSeriesList({
				type: 10
			});
			let boxSeries = getSeriesList({
				type: 20
			});
			let vintageSeries = getSeriesList({
				type: 30
			});
			let res = await Promise.all([collectionSeries, boxSeries, vintageSeries])
			let data = {
				collectionSeries: res[0].data,
				boxSeries: res[1].data,
				vintageSeries: res[2].data
			}
			commit('setSeries', data)
			return Promise.resolve(data)
		}
	}
}